package dse.messages.locatedataobj;

import java.util.LinkedList;

import dse.Cluster;
import dse.Experiment;
import dse.ExperimentRecorder;
import dse.messages.Message;
import dse.messages.MessageHandler;
import dse.messages.MessageSender;

public class ClustersThatMightHaveDataObjectMessageHandler
extends MessageSender
implements MessageHandler
{
	private LinkedList<Cluster> clusters;
	private LocateClustersWithDataObjectRequester requester;
	
	
	public ClustersThatMightHaveDataObjectMessageHandler (
			Experiment experiment, 
			LinkedList<Cluster> clusters,
			LocateClustersWithDataObjectRequester requester
			)
	{
		super(experiment);
		
		this.clusters = clusters;
		this.requester = requester;
	}

	
	
	public boolean acceptMessage (
			Message message
			)
	{
		return true;
	}
	
	public void messageReceived (
			ExperimentRecorder recorder, 
			Message message,
			double timeLeft
			)
	{
		recorder.debug(this, "msgRcvd: " + message, timeLeft);
		// Now we just simply let the reqiester do its work
		requester.clustersThatMightHaveDataObject(recorder, clusters, timeLeft);
	}
	
	public void messageInterupted (
			ExperimentRecorder recorder,
			Message message, 
			double timeLeft
			)
	{
		recorder.debug(this, "msgIntrpt: " + message, timeLeft);
		requester.clustersThatMightHaveDataObject(recorder, null, timeLeft);
	}
}
